import Mock from "mockjs"
import listObj from '../db/index.json'
// 内存模拟数据

const arr = []
for (let i = 0; i < 10; i++) {
  arr.push({
    id: Mock.mock("@id"),
    name: Mock.mock("@name"),
    price: Mock.mock("@price"),
    count: Mock.mock("@count"),
    thumb: Mock.mock("@thumb"),
  })
}
arr = listObj.cart
console.log('arr ------',arr);
export default [
  {
    url: "/cart",
    method: "get",
    response: () => {
      return arr
    },
  },
  {
    url: "/cart/:id",
    method: "patch",
    response: ({ query, body }) => {
      const item = arr.find((item) => item.id === query.id)
      if (item) {
        item.name = body.name
        item.price = body.price
        item.place = body.place
        item.count = body.count
        item.thumb = body.thumb
        return { success: true }
      } else {
        return { success: false }
      }
    },
  },
]
